﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DeliciousPlugin
{
    public partial class frmOptions : Form
    {
        private PluginSettings m_settings;

        public frmOptions(PluginSettings settings)
        {
            InitializeComponent();
            m_settings = settings;
            txbxPassword.Text = m_settings.Password;
            txbxUsername.Text = m_settings.UserName;
            chbxAutoPost.Checked = m_settings.AutomaticallyPost;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string uname = txbxUsername.Text;
            string pword = txbxPassword.Text;
            if (uname.Length == 0 || pword.Length == 0)
            {
                MessageBox.Show("Please enter a username *and* password.", "Big Fat Hairy Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            m_settings.AutomaticallyPost = chbxAutoPost.Checked;
            m_settings.Password = pword;
            m_settings.UserName = uname;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void lnkForgetMe_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you wish to remove these credentials?", "I need info boss", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.No)
                return;
            m_settings.Password = "";
            m_settings.UserName = ""; 
            txbxPassword.Text = "";
            txbxUsername.Text = "";
        }
    }
}
